using System.IO;
using YatFram;
using YatFram.Browser.Watin;

namespace Yatfram.Tests.Browser
{
    public static class WatinBrowserActions
    {
        public static YatFram<Context> open_my_browser_at(this YatFram<Context> yf, string relativeFilePath)
        {
            var testfile = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
            var page = Path.Combine(Path.Combine(Path.GetDirectoryName(testfile), "testsite"), relativeFilePath);
            
            return yf.Do(c => c.Browser = new WatinBrowser(page));
        }

        public static YatFram<Context> add_the_text_for(this YatFram<Context> yf, string cssSelector, string newValue)
        {
            return yf.Do(c => c.Browser.FindTextBox(cssSelector).EnterText(newValue));
        }

        public static YatFram<Context> select_the_value(this YatFram<Context> yf, string cssSelector, string newValue)
        {
            return yf.Do(c => c.Browser.FindSelect(cssSelector).Select(newValue));
        }

        public static YatFram<Context> select_the_radio_option(this YatFram<Context> yf, string name, string newValue)
        {
            return yf.Do(c => c.Browser.FindRadio(name).Select(newValue));
        }

        public static YatFram<Context> check_the_checkbox_option(this YatFram<Context> yf, string name, string newValue)
        {
            return yf.Do(c => c.Browser.FindCheckbox(name).Check(newValue));
        }

        public static YatFram<Context> uncheck_the_option(this YatFram<Context> yf, string name, string newValue)
        {
            return yf.Do(c => c.Browser.FindCheckbox(name).Uncheck(newValue));
        }
    }
}